package com.ohuang.util_h.replaceActivity;

import android.content.Intent;

public class NameHandleIntent implements HandleIntent{

    String oldClassName;
    String newClassName;

    public boolean enable = false;

    public  NameHandleIntent(String oldName, String newName){
        try {
            Class<?> clazz = Class.forName(newName);
            newClassName = newName;
            oldClassName = oldName;
            if (!newClassName.equals(oldClassName)) {
                enable = true;
            }
        } catch (ClassNotFoundException e) {

        }

    }
    @Override
    public boolean onIntent(Intent intent) {
        try {
            if (enable) {
                String className = intent.getComponent().getClassName();
                String packageName = intent.getComponent().getPackageName();
                if (className.equals(oldClassName)) {
                    intent.setClassName(packageName,newClassName);
                    return true;
                }
            }
        }catch (Throwable e) {

        }

        return false;
    }
}
